package cn.edu.cqvie.ssm.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.log4j.Log4j2;

/**
 * 首页链接
 *
 * @author xyz
 */
@SuppressWarnings("serial")
@WebServlet("/index")
@Log4j2
public class IndexServlet extends HttpServlet{

    public IndexServlet() {
		super();
        log.info("IndexServlet constructor");
	}

	@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        log.info("IndexServlet doGet");
        doPost(req, resp);
    }

	
	
    @Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        log.info("IndexServlet service");
    	super.service(req, resp);
	}

	@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        log.info("IndexServlet doPost");

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.print("this is my first servlet page");
        pw.flush();
        pw.close();
    }

    @Override
    public void destroy() {
        log.info("IndexServlet destroy");
        super.destroy();
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        log.info("IndexServlet init");
        super.init(config);
    }
}
